package apiday03;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
// 泛型演示
public class GenericDemo {
    public static void main(String[] args) {
        Collection<Point> c = new ArrayList<>();
        c.add(new Point(1,2));
        c.add(new Point(3,4));
        c.add(new Point(5,6));
        c.add(new Point(7,8));
        c.add(new Point(9,0));
        // c.add("one"); 编译错误 类型不匹配

        Iterator<Point> it = c.iterator();
        while (it.hasNext()){
            Point p = it.next(); // 自动补齐
            System.out.println(p);
        }

        for (Point p : c){
            System.out.println(p);
        }

        /*
        Collection<String> c = new ArrayList<>(); // 泛型集合
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        // c.add(new Point(1,2)); 编译错误 违背泛型集合类型
        System.out.println(c);

        Iterator<String> it = c.iterator(); // 和泛型集合一致的类型
        while (it.hasNext()){
            String str = it.next();
            System.out.println(str);
        }

        for (String str : c){
            System.out.println(str);
        }
         */
    }
}
